package com.tanhua.admin.mapper;

import cn.hutool.core.date.DateTime;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tanhua.model.domain.Analysis;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * @Author: cl
 * @Date: 2022/5/17 - 05 - 17
 * @Description:
 */

/**
 * 日志统计表
 */
public interface AnalysisMapper extends BaseMapper<Analysis> {

    /**
     * 指定时间某一字段的数据和
     * #{} 对应的变量自动加上单引号 '',所以sum中占位符要换成${column}
     *
     * @param thisDate
     * @param column
     * @return
     */
    @Select("select sum(${column}) from tb_analysis where record_date = #{thisDate}")
    Long sumAnalysisDataDay(@Param("thisDate") String thisDate, @Param("column") String column);

    /**
     * 指定时间段的某一字段数据和
     *
     * @param today
     * @param thatDate
     * @param column
     * @return
     */
    @Select("select sum(${column}) from tb_analysis where record_date >= #{thatDate} and " +
            "record_date <= #{today}")
    Long sumAnalysisData(@Param("today") DateTime today, @Param("thatDate") String thatDate, @Param("column") String column);
}
